var a = require("../../utils/api.js"), t = getApp();

Page({
    data: {
        optionList: [ {
            status: 0,
            name: "全部"
        }, {
            status: 20,
            name: "待配送"
        }, {
            status: 30,
            name: "待提货"
        }, {
            status: 100,
            name: "已完成"
        } ],
        two: [ {
            num: 0,
            name: "全部"
        }, {
            num: 1,
            name: "到店自提"
        }, {
            num: 2,
            name: "团长配送"
        }, {
            num: 3,
            name: "快递配送"
        } ],
        containerHeight: 0,
        scrollTop: 0,
        currentTab: 0,
        curCode: 0,
        data: [],
        loading: !1,
        page: 2,
        curtwo: 0,
        showLoding: !1
    },
    onLoad: function(e) {
        var o = this, n = wx.getSystemInfoSync(), r = e.curtwo ? e.curtwo : 0;
        this.setData({
            currentTab: e.tabStatus || "0",
            containerHeight: n.windowHeight - Math.round(n.windowWidth / 375 * 55)
        });
        for (var s = 0; s < o.data.optionList.length; s++) o.data.currentTab == o.data.optionList[s].status && o.setData({
            curCode: s
        });
        0 == r ? a.getTeamOrder({
            openid: t.globalData.openid,
            status: o.data.currentTab
        }).then(function(a) {
            console.log(a), 0 == a.errno ? o.setData({
                data: a.data,
                showLoding: !0
            }) : o.setData({
                showLoding: !0
            });
        }) : a.getTeamOrder({
            openid: t.globalData.openid,
            status: o.data.currentTab,
            type: r
        }).then(function(a) {
            console.log(a), 0 == a.errno && o.setData({
                data: a.data,
                showLoding: !0
            });
        }), o.setData({
            curtwo: r
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        });
    },
    switchNav: function(a) {
        var t = this, e = a.currentTarget.dataset.current, o = t.data.optionList;
        console.log(a);
        for (var n, r = 0; r < o.length; r++) e == o[r].status && (n = r);
        t.setData({
            currentTab: e,
            curCode: n,
            curtwo: t.data.curtwo
        });
    },
    bindChange: function(e) {
        var o = this, n = e.detail.current, r = o.data.optionList;
        console.log(n), o.setData({
            showLoding: !1
        });
        for (var s, d = 0; d < r.length; d++) n == d && (s = r[d].status);
        o.setData({
            currentTab: s,
            curtwo: o.data.curtwo,
            data: ""
        }), console.log(o.data.currentTab), a.getTeamOrder({
            openid: t.globalData.openid,
            status: o.data.currentTab,
            type: o.data.curtwo
        }).then(function(a) {
            console.log(a), 0 == a.errno ? o.setData({
                data: a.data,
                page: 2,
                loading: !1,
                showLoding: !0
            }) : o.setData({
                loading: !1,
                data: "",
                page: 2,
                showLoding: !0
            });
        });
    },
    getCurrentList: function(e) {
        var o = this;
        o.setData({
            loading: !0,
            tip: ""
        }), console.log(o.data.currentTab);
        var n = o.data.page, r = o.data.curtwo;
        a.getTeamOrder({
            openid: t.globalData.openid,
            page: n,
            status: o.data.currentTab,
            type: r
        }).then(function(a) {
            if (console.log(a), 0 == a.errno) {
                var t = o.data.data.concat(a.data);
                n = parseInt(n) + parseInt(1), o.setData({
                    data: t,
                    page: n
                });
            } else o.setData({
                loading: !1
            });
        });
    },
    viewDetail: function(a) {
        wx.navigateTo({
            url: "./groupOrderDetail?id=" + a.currentTarget.dataset.id
        });
    },
    twochange: function(e) {
        var o = this, n = e.currentTarget.dataset.type;
        console.log(n), 0 == n ? a.getTeamOrder({
            openid: t.globalData.openid,
            status: o.data.currentTab,
            type: n
        }).then(function(a) {
            console.log(a), 0 == a.errno ? (a.data.length, o.setData({
                data: a.data,
                page: 2,
                loading: !1
            })) : o.setData({
                loading: !1,
                data: "",
                page: 0
            });
        }) : a.getTeamOrder({
            openid: t.globalData.openid,
            status: o.data.currentTab,
            type: n
        }).then(function(a) {
            console.log(a), 0 == a.errno ? o.setData({
                data: a.data,
                page: 2,
                loading: !1
            }) : o.setData({
                loading: !1,
                data: "",
                page: 2
            });
        }), o.setData({
            curtwo: n,
            scrollTop: 0
        });
    }
});